<?php
class NewsAction extends Action{
   public function _initialize(){//初始化
		R("Home.Public","top");
		R("Home.Public","bottom");
   }
   public function index(){//商城公告
	   import("ORG.Com.DiyCache");
	   $mycache=new DiyCache;
	   if(!$mycache->is_cached()){//处理自定义缓存
	     //商城公告
		 $typeid = 36;
		 $article = M("article");
		 Vendor("LJW.page");
		 $map["typeid"] = $typeid;
		 $count = $article->where($map)->count();
		 $mypage = new page($count,10,3,U('News/index'));
		  //分页
		  //上一页   下一页 
		 if($mypage->absolutepage <> 1) $prev_page="<span class='next_bz'><a href='".$mypage->url."/p/".($mypage->absolutepage-1)."'>上一页</a></span>";	
		 if($mypage->absolutepage <> $mypage->pagenum) $next_page="<span class='next_bz'><a href='".$mypage->url."/p/".($mypage->absolutepage+1)."'>下一页</a></span>";
		 
		  
		 $start=$mypage->absolutepage-4;
		 if($start<1)$start=1;
		 $end=$start+8;
		 if($end>$mypage->pagenum) $end=$mypage->pagenum;
			 
		 $start_url=$mypage->url."/p/".$start;
		 $end_url=$mypage->url."/p/".$end;
			 
		 $f_url=$mypage->url."/p/1";//第一页
		 $l_url=$mypage->url."/p/".$mypage->pagenum;//最后一页
			 
		 if($start<>1)$f_str="<a href='$f_url'>1</a><a href='#'>…</a>";
		 if($end<>$mypage->pagenum)$l_str="<a href='#'>…</a><a href='$l_url'>".$mypage->pagenum."</a>";
			 
		 for($i=$start;$i<=$end;$i++){
			if($mypage->absolutepage == $i){
			   $m_str.="<a href='".$mypage->url."/p/".$i."' class='on_link' >$i</a>";
			}else{
			   $m_str.="<a href='".$mypage->url."/p/".$i."'>$i</a>";	
			}
			
		 }
		 $div_str.=$prev_page.$f_str.$m_str.$l_str.$next_page;
		 
		 if(!empty($count))$this->assign("divpage",$div_str);
		 
		 $a_list = $article->where($map)->limit($mypage->start.",".$mypage->pagesize)->order("datetime desc")->findAll();
		 $this->assign("a_list",$a_list);
	   
	     if(C("diy_cache"))$mycache->create_cache($this->fetch());//创建缓存
	     $this->display();
	   }
   }
   public function news_info(){//新闻详细
       /*安全处理*/
	   checkget();
	   $id=$_GET["id"];
	   if(empty($id)||!is_numeric($id))alert('参数错误');
	   /*安全处理*/
	   
	   import("ORG.Com.DiyCache");
	   $mycache=new DiyCache;
	   if(!$mycache->is_cached()){//处理自定义缓存
	     
	     $article = M("article");
		 $a_info = $article->where("id = $id")->find();
		 $this->assign("a_info",$a_info);
		 
	     if(C("diy_cache"))$mycache->create_cache($this->fetch());//创建缓存
	     $this->display();
	   }
   }
   public function service(){//售后服务
      /*安全处理*/
	  checkget();
	  $typeid = $_GET["typeid"];
	  if(!empty($typeid)&&!is_numeric($typeid))alert('参数错误');
	  /*安全处理*/
      import("ORG.Com.DiyCache");
	  $mycache=new DiyCache;
	  if(!$mycache->is_cached()){//处理自定义缓存
          //先读取售后服务分类
		  $sysclass = M("sysclass");
		  $parid = 40;
		  $child_type = $sysclass->where("parid = $parid")->order("sequence desc")->findAll();
		  $this->assign("child_type",$child_type);
		  
		  if(empty($typeid)) $typeid = $child_type[0]['id'];
		  
		  $this->assign("typeid",$typeid);
		  
		  //读取文章信息
		  $article = M("article");
		  $a_info = $article->where("typeid = $typeid")->order("sequence desc")->find();
		  $this->assign("a_info",$a_info);
			  
		  if(C("diy_cache"))$mycache->create_cache($this->fetch());//创建缓存
	      $this->display();
	   }
   }
   
   public function guide(){//购物指南
	  /*安全处理*/
	  checkget();
	  $typeid = $_GET["typeid"];
	  if(!empty($typeid)&&!is_numeric($typeid))alert('参数错误');
	  /*安全处理*/
      import("ORG.Com.DiyCache");
	  $mycache=new DiyCache;
	  if(!$mycache->is_cached()){//处理自定义缓存
          //先读取购物指南分类
		  $sysclass = M("sysclass");
		  $parid = 39;
		  $child_type = $sysclass->where("parid = $parid")->order("sequence desc")->findAll();
		  $this->assign("child_type",$child_type);
		  
		  if(empty($typeid)) $typeid = $child_type[0]['id'];
		  
		  $this->assign("typeid",$typeid);
		  
		  //读取文章信息
		  $article = M("article");
		  $a_info = $article->where("typeid = $typeid")->order("sequence desc")->find();
		  $this->assign("a_info",$a_info);
			  
		  if(C("diy_cache"))$mycache->create_cache($this->fetch());//创建缓存
	      $this->display();
	   }
   }
   
   public function contact(){//联系我们
      import("ORG.Com.DiyCache");
	  $mycache=new DiyCache;
	  if(!$mycache->is_cached()){//处理自定义缓存
	      $article = M("article");
		  $typeid = 41;
		  $a_info = $article->where("typeid = $typeid")->order("sequence desc")->find();
		  
		  $this->assign("a_info",$a_info);
		  
	      
	      if(C("diy_cache"))$mycache->create_cache($this->fetch());//创建缓存
	      $this->display();
	   }
   }
}
?>